package com.zq.learn.springbatch.quartz;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static org.quartz.CronScheduleBuilder.cronSchedule;

/**
 * ScheduleConfig
 *
 * @author ZhangQi
 * @date 2020/2/17
 */
@Configuration
public class ScheduleConfig {
  @Bean
  public JobDetail task2JobDetail() {
    return JobBuilder.newJob(Task2.class)
      .withIdentity("task2")
      .storeDurably(true)
      .build();
  }

  @Bean
  public Trigger task2Trigger() {
    return TriggerBuilder.newTrigger()
      .forJob(task2JobDetail())
      .withIdentity("trigger2")
      .withSchedule(cronSchedule("*/4 * * * * ?"))
      .build();
  }
}
